<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>产品添加</title>
<!-- BEGIN 页面公共文件 -->
<load href="__COMMON__/css/init.css" />
<load href="__COMMON__/css/font-icons.css" />
<load href="__COMMON__/js/jquery.min.js" />
<!-- END 页面公共文件 -->


<!-- BEGIN 当前页面的css 和js -->
<load href="__COMMON__/css/tools/easydialog.css" />
<load href="__ADMIN_CSS__/common.css" />
<load href="__ADMIN_CSS__/goods/attr_add.css" />
<load href="__COMMON__/js/tools/easydialog.min.js" />
<load href="__COMMON__/js/tools/Validator.js" />
<!-- END 当前页面的css 和js -->
<style type="text/css">
.forminfo select{
	min-width: 120px;
	height: 30px;
}
</style>
</head>
<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="{:U('Index/main')}">首页</a></li>
    <li><a href="javascript:void(0)">产品分类添加</a></li>
    </ul>
    <a class="reload" href="javascript:void(0)" onclick="window.location.reload()"><i class="fa fa-refresh"></i>重载此页面</a>
    </div>

    <div class="formbody">
    <div class="formtitle">
    	<span>产品分类信息添加</span>
		<a href="{:U('Goods/category')}"><i class="fa fa-reply"></i>返回产品分类列表</a>
		</div>    
    <ul class="forminfo">
    <li><label><b>*</b>分类级别</label>
    	<select name="parentid">
    		<option value="0">顶级分类</option>
    		<if condition="$cates">
			<foreach name="cates" item="cate">
    			<option value="{$cate.id}">{$cate.separatechar}{$cate.catename}</option>
			</foreach>
    		</if>
    	</select>
    </li>
    <li><label><b>*</b>分类名称</label><input name="catename" type="text" class="dfinput" maxlength="60" /><i placeholder="标题不小于4个字符且不能超过60个字符" >标题不小于4个字符且不能超过60个字符</i></li>
     <li><label><b>&nbsp;</b>关键字</label><input name="keywords" type="text" class="dfinput" /><i placeholder="多个关键字用空格隔开" >多个关键字用空格隔开，建议填写，利于搜索引擎收录网站</i></li>
    <li  class="lab-desc"><label><b>&nbsp;</b>分类描述</label><cite><textarea name="description" value="" class="description"></textarea><div class="count-text">还可输入<span class="text-num">200</span>个字</div><i>描述不超过200字，建议填写，利于搜索引擎收录网站</i></cite></li>
     <li><label><b>&nbsp;</b>是否显示</label>
	<input name="isshow" type="hidden" value="1" />
	<cite class="checkshow">
		<a href="javascript:void(0)" class="show"><i class="fa fa-check-square"></i>立即显示</a>
		<a href="javascript:void(0)" class="not_show"><i class="fa fa-square-o"></i>暂不显示</a>
	</cite>
	<i>选择“显示”则前端才可查看到此分类，“不显示”则不能查看</i>
	</li>
     <li><label><b>&nbsp;</b>导航显示</label>
	<input name="showinnav" type="hidden" value="1" />
	<cite class="checkshow">
		<a href="javascript:void(0)" class="show"><i class="fa fa-check-square"></i>启用</a>
		<a href="javascript:void(0)" class="not_show"><i class="fa fa-square-o"></i>不启用</a>
	</cite>
	<i>选择“启用”则前端顶部导航会出现此分类，“不启用”则导航不显示</i>
	</li>     
    <li>
    <label><b>&nbsp;</b>排序设置</label>
    <input name="sortorder" type="text" class="dfinput sort" value="10" />
    <i placeholder="请输入整数">请输入整数</i>
    </li>    
    <li><label>&nbsp;</label><input name="submit" type="button" class="submit submitable" value="添加分类" />
	<i placeholder=""></i>
	</li>
    </ul>
</div>
</body>
</html>
<script type="text/javascript">
var $postUrl="{:U('Goods/cateAdd')}";
var $parentid=$('select[name="parentid"]'),
	  $catename=$('input[name="catename"]'),
	  $keywords=$('input[name="keywords"]'),
	  $description=$('textarea[name="description"]'),
	  $isshow=$('input[name="isshow"]'),
	  $showinnav=$('input[name="showinnav"]'),
	  $sortorder=$('input[name="sortorder"]');


/****************** BEGIN 效果表现区**************/
//单选按钮模拟
$(".checkshow").find("a").click(function() {
		$(this).find("i.fa").removeClass("fa-square-o").addClass("fa-check-square");
		$(this).siblings("a").find("i.fa").removeClass("fa-check-square").addClass("fa-square-o");
		if ($(this).hasClass("show")) {
			$show = 1;
		} else {
			if ($(this).hasClass("not_show")) {
				$show = 0;
			} else {
				$show = 1;
			}
		}
		$(this).parent().siblings('input[type="hidden"]').val($show);
});
var totalNum = $description.siblings("div").find("span").text();
wordCount($description);
$description.keyup(function() {
wordCount($(this));
});
/****************** END 效果表现区**************/

/************** BEGIN 数据校验区****************/
$catename.blur(function (){
	func_catename($(this));
})
$keywords.blur(function (){
	func_keywords($(this));
})
$description.blur(function (){
	func_description($(this));
})
$sortorder.blur(function (){
	getNumber($(this));
})
/************** END 数据校验区****************/

/************* BEGIN 数据处理区***************/
//表单提交
$('input[name="submit"]').click(function (){
	var $this=$(this);
	if($this.hasClass("submit-disable")) return false;
	var bool_catename= func_catename($catename),
		  bool_keywords= func_keywords($keywords),
		  bool_description= func_description($description);
	if(bool_catename && bool_keywords && bool_description){
		var $data={
				parentid: $parentid.val(),
				catename: $catename.val(),
				keywords: $keywords.val(),
				description: $description.val(),
				sortorder: $sortorder.val(),
				isshow: $isshow.val(),
				showinnav: $showinnav.val()
		}
		$this.siblings("i").html('<span class="doing">正在提交，请稍后……</span>');
		$this.removeClass("submitable").addClass("submit-disable");
		$.post($postUrl,$data, function (back){
			if(back.status==1){
				easyDialog.open({
					container : {
						header : "消息提醒窗口",
						content : "成功增加一个产品分类，你可以：<br />前往查看分类列表，或者继续添加分类！",
						yesFn : function() {
							window.location.href = window.location.href;
						},
						noFn : function() {
							window.location.href = back.redirecturl;
						}
					}
				});
				$("#easyDialogYesBtn").text("继续添加");
				$("#easyDialogNoBtn").text("查看列表");
			}else{
				var time= (back.waittime) ? back.waittime*1000 : 3000;				
				easyDialog.open({
					container : {
						header: '消息提醒窗口',
						content : back.data
					},
					autoClose : time
				});		
				$this.siblings("i").html('');
				$this.removeClass("submit-disable").addClass("submitable");		
			}
			
		}, 'json')
	}else{
		setTips($(this), "表单数据还有错误，请检查！");
		return false;
	}
})

/************* END 数据处理区***************/
 
/************** BEGIN 函数集成****************/
 function func_catename(o){
	var value=o.val();
	if (is_empty(value)) {
		setTips(o, "分类名称不能为空！");
		return false;
	} else {
		if (has_length_error(value, 4, 60)) {
			setTips(o, "名称长度为4-60个字符，请检查！");
			return false;
		} else {
			setTips(o, "", true);
			return true;
		}
	}
}
function func_keywords(o){
	var value=o.val();	
		if (has_length_error(value, 0, 100)) {
			setTips(o, "关键词长度为0-100个字符，请检查！");
			return false;
		} else {
			setTips(o, "", true);
			return true;
		}
}
function func_description(o){
	var value=o.val();
		if (has_length_error(value, 0, 200)) {
			setTips(o, "分类描述长度为0-200个字符，请检查！");
			return false;
		} else {
			setTips(o, "", true);
			return true;
		}	
}
 
function getNumber(o){
	var value=trimValue(o.val());
	value = value.replace(/[^0-9]/ig,"");
	var reg=/\d/g;
	if(reg.test(value))
	o.val(value);
	else
	o.val(10);
}

function wordCount(o) {
	var nowLen = o.val().length;
	var thislen = totalNum - nowLen;
	if (thislen < 0) {
		thislen = " 已超出" + thislen;
	}
	o.siblings("div").find("span").text(thislen);
}

 function setTips(o, tips, isDef) {
		isDef = (isDef == null) ? false : true;
		o.siblings("i").html("");
		if (isDef) {
			if ("" !== tips) {
				var defTips = tips;
			} else {
				var defTips = o.siblings("i").attr("placeholder");
			}
			if (typeof defTips == "undefined") {
				defTips = "通过校验";
			}
			o.siblings("i").text(defTips);
		} else {
			o.siblings("i").html('<i style="color: #DD2D28;font-size:15px;padding-right: 5px;" class="fa fa-exclamation-circle"></i><span style="color: #D31B26;">'+ tips + "</span>");
		}
	}

/************** END 函数集成****************/
</script>

